<?php
/**
 * Created by Dumitru Russu
 * User: developer
 * Date: 10/30/12
 * Time: 3:35 PM
 * To change this template use File | Settings | File Templates.
 */
class Db_Products_DesignerErrorMessage extends Common{
	protected static $tableName = TAB_DESIGNER_ERROR_MESSAGES;
	protected static $dbFields = array(
		'id',
		'dem_parent_id',
		'dem_title',
		'dem_content',
		'dem_module',
		'deleted'
	);

	/**
	 * @var Db_Products_DesignerErrorMessage
	 */
	public $objectArray;

	public $id;
	public $dem_parent_id;
	public $dem_title;
	public $dem_content;
	public $dem_module;
	public $deleted;
	function __construct($value = null, $fieldName = null) {
		parent::__construct($value, $fieldName);
	}

	public static function getAllDesignerErrorMessages($parentId = 0) {
		$sqlJoin = null;
		$fieldName = null;
		if($parentId == 0) {
			$parentId = 0;
			$sqlJoin = 'LEFT JOIN ' . self::$tableName . ' AS `tem` ON `tem`.`dem_parent_id` = `dem`.`id` AND `tem`.`deleted` = 0 ';
			$fieldName = ', `tem`.`dem_parent_id` AS `used`';
		}
		$sql = "SELECT `dem`.* {$fieldName} FROM ?f AS `dem`
				{$sqlJoin}
				WHERE `dem`.`deleted` = 0 AND `dem`.`dem_parent_id` = ?
				GROUP BY `dem`.`id`;";
		return self::$DB->select($sql, self::$tableName, $parentId);
	}
}
